<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleleaf.org">
<head th:insert="base">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="/back/user/welcome">首页</a>
            <a href="#">买家中心</a>
            <a>
              <cite>订单列表</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <input type="hidden" id="buyerId" name="buyerId" th:value="${buyerId}"/>
                <div class="layui-card-body ">
                    <div class="layui-form layui-col-space5">
                        <div class="layui-input-inline layui-show-xs-block">
                            <select id="orderStatus">
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" readonly  autocomplete="off" placeholder="创建开始日期" id="createTimeStart">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" readonly  autocomplete="off" placeholder="创建截止日期" id="createTimeEnd">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" id="formSearch"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-hide" id="tableId" lay-filter="tableId"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="operations">
    {{#if(d.orderStatus == '0' || d.orderStatus == '1'){}}
        <a class="layui-btn layui-btn-xs" lay-event="send" title="确认送达"><i class="layui-icon layui-icon-release"></i>确认送达</a>
    {{#}}}
    <a class="layui-btn layui-btn-xs" lay-event="evaluate" title="评价"><i class="layui-icon layui-icon-reply-fill"></i>评价</a>
    <a class="layui-btn layui-btn-xs" lay-event="complaint" title="投诉"><i class="layui-icon layui-icon-survey"></i>投诉</a>
    <a class="layui-btn layui-btn-xs" lay-event="viewEvaluate" title="查看评价"><i class="layui-icon layui-icon-dialogue"></i>查看评价</a>
    <a class="layui-btn layui-btn-xs" lay-event="viewComplaint" title="查看投诉"><i class="layui-icon layui-icon-share"></i>查看投诉</a>
</script>
<script type="text/html" id="sellerInfo">
    <a onclick="xadmin.open('卖方信息','/back/userInfo/view?id={{d.sellerId}}')" class="layui-table-link">{{d.sellerName}}</a>
</script>
<script type="text/html" id="buyerInfo">
    <a onclick="xadmin.open('买方信息','/back/userInfo/view?id={{d.buyerId}}')" class="layui-table-link">{{d.buyerName}}</a>
</script>
<script th:inline="none">
    layui.use(['table','form','util','tool','laydate','enums'], function(){
        var table = layui.table;
        var $ = layui.jquery;
        var form = layui.form;
        var util = layui.util;
        var tool = layui.tool;
        var laydate = layui.laydate;
        var enums = layui.enums;
        var baseUrl = "/back/orderInfo";
        init_form();
        table.render({
            elem: '#tableId'
            ,id:'tableReload'
            ,url: baseUrl + '/getBuyList'
            ,limit:10
            ,limits:[10,20,50]
            ,method:'post'
            ,toolbar:'#toolbar'
            ,defaultToolbar: ['print']
            ,title: '订单列表'
            ,cols: [[
                {field: '', title: '序号',width:50,type:'numbers'}
                ,{field:'goodName', title:'拍品名称',type: 'text',width:200}
                ,{field:'sellerName', title:'卖方姓名',type: 'text',width:200, templet: '#sellerInfo'}
                ,{field:'buyerName', title:'买方姓名',type: 'text',width:200, templet: '#buyerInfo'}
                ,{field:'orderStatusDesc', title:'订单状态',type: 'text',width:200}
                ,{field:'createTime', title:'注册时间',type: 'text',width:200,templet:function (d) {
                        if(d.createTime){
                            return util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss")
                        }
                        return "";
                    }}
                ,{title:'操作', toolbar: '#operations',width:400}
            ]]
            ,page: true
        });

        //行工具栏事件
        table.on('tool(tableId)', function(obj){
            var data = obj.data;
            switch (obj.event) {
                case 'send':
                    layer.confirm('确认拍品已经送达？', function(index){
                        var res = tool.submit(baseUrl + '/send',{id:data.id});
                        if(res.code == return_200){
                            layer.msg(res.msg, {
                                    icon: msg.success,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }else {
                            layer.msg(res.msg, {
                                    icon: msg.error,
                                    time: 2000
                                },
                                function(){
                                    callBack();
                                }
                            );
                        }
                    });
                    break;
                case 'evaluate':
                    xadmin.open('订单评价','/back/orderEvaluate/add?id='+data.id+'&evaluateDir=0',400,300);
                    break;
                case 'complaint':
                    xadmin.open('订单投诉', '/back/orderComplaint/add?id='+data.id,400,300);
                    break;
                case 'viewEvaluate':
                    xadmin.open('订单评价', '/back/orderInfo/viewEvaluate?id='+data.id);
                    break;
                case 'viewComplaint':
                    xadmin.open('订单投诉', '/back/orderInfo/viewComplaint?id='+data.id);
                    break;
            }
        });

        //条件查询
        $('#formSearch').on('click', function(){
            table.reload('tableReload', {
                page: {curr: 1 }
                ,where:  getQueryParams()
            });
        });

        /**
         * 查询的参数
         * @returns {{}}
         */
        function getQueryParams() {
            return {
                orderStatus:$("#orderStatus").val().trim()
                ,buyerId:$("#buyerId").val().trim()
                ,createTimeStart:$("#createTimeStart").val().trim()
                ,createTimeEnd:$("#createTimeEnd").val().trim()
            }
        }

        /**
         * 初始化页面
         */
        function init_form() {
            enums.createSelectByEnum('orderStatus','EnumOrderStatus',null,null,'请选择订单状态');
            form.render();
            laydate.render({
                elem: '#createTimeStart'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#createTimeEnd'
                ,type: 'datetime'
            });
        }
        /**
         * 回调函数
         */
        function callBack() {
            $("#formSearch").click();
        }
    });
</script>
</body>
</html>